﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    private const int MaxSeatsPlusOne = 11;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void PickSeats(object sender, EventArgs e)
    {
        ResetAllSeats();
        ChooseSeats(sender);
    }

    private void ResetAllSeats()
    {
        int offsetSeat = 1;
        string[] seatRows = {"a", "b"};

        foreach (string s in seatRows)
        {
            while (offsetSeat < MaxSeatsPlusOne)
            {
                Button b = (Button)this.FindControl(s + offsetSeat);
                b.CssClass = "greenSeat";
                offsetSeat++;
            }
            offsetSeat = 1;
        }
    }

    private void ChooseSeats(object sender)
    {
        Button clickedSeat = (Button)sender;
        int clickedSeatId = Convert.ToInt32(clickedSeat.ID.Substring(1));
        string seatRow = clickedSeat.ID.Substring(0, 1);
        int noOfSeats = clickedSeatId + Convert.ToInt32(txtNo.Text);

        if ((noOfSeats <= MaxSeatsPlusOne) && (clickedSeatId > 2 || clickedSeatId < 2) && ((MaxSeatsPlusOne - noOfSeats > 1) || (MaxSeatsPlusOne - noOfSeats < 1)))
        {
            while (clickedSeatId < noOfSeats)
            {
                Button b = (Button)this.FindControl(seatRow + clickedSeatId);
                b.CssClass = "yellowSeat";

                clickedSeatId++;
            }
        }
    }
}